package com.qingfeng.medical.controller.admin.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qingfeng.currency.dozer.DozerUtils;
import com.qingfeng.medical.base.controller.BaseController;
import com.qingfeng.medical.base.log.annotation.Log;
import com.qingfeng.medical.base.log.enums.BusinessType;
import com.qingfeng.medical.base.result.Result;
import com.qingfeng.medical.biz.order.domain.dto.ExaminationSaveDTO;
import com.qingfeng.medical.biz.order.domain.dto.ExaminationUpdateDTO;
import com.qingfeng.medical.biz.order.domain.entity.Examination;
import com.qingfeng.medical.biz.order.service.ExaminationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 体检报告表
 *
 * @author 清风学Java
 * @date 2023-05-16 00:23:14
 */
@Api(tags = "体检报告表管理")
@RestController
@RequestMapping("/admin/info/examination")
@CrossOrigin
@Validated
public class ExaminationController extends BaseController {

    @Autowired
    private ExaminationService examinationService;
    @Autowired
    private DozerUtils dozerUtils;

    @ApiOperation(value = "保存体检报告表信息", notes = "保存体检报告表信息")
    @PostMapping("/save")
    @Log(title = "体检报告管理", businessType = BusinessType.INSERT, message = "保存体检报告表信息")
    public Result save(@RequestBody @Validated ExaminationSaveDTO examinationSaveDTO) {
        examinationService.save(dozerUtils.map2(examinationSaveDTO, Examination.class));
        return Result.ok();
    }

    @ApiOperation(value = "修改体检报告表信息", notes = "修改体检报告表信息")
    @PutMapping("/update")
    @Log(title = "体检报告表管理", businessType = BusinessType.UPDATE, message = "修改体检报告表信息")
    public Result update(@RequestBody @Validated ExaminationUpdateDTO examinationUpdateDTO) {
        examinationService.updateById(dozerUtils.map2(examinationUpdateDTO, Examination.class));
        return Result.ok();
    }

    @ApiOperation(value = "查询体检报告信息", notes = "查询体检报告信息")
    @GetMapping("/info/{orderId}")
    @Log(title = "体检报告表管理", businessType = BusinessType.SELECT, message = "修改体检报告表信息")
    public Result<Examination> info(@PathVariable("orderId") Long orderId){
        return Result.ok(examinationService.getOne(
                new LambdaQueryWrapper<Examination>()
                        .eq(Examination::getOrderId, orderId)
        ));
    }

}
